package com.autcar.training.dao;

import com.autcar.training.entity.Order;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.springframework.web.bind.annotation.PathVariable;

import java.util.List;

/**
 * @ProjectName: training
 * @Package: com.autcar.training.dao
 * @ClassName: OrderMapper
 * @Author: YHHHH
 * @Description: 订单的CRUD
 * @Date: 2020/8/28 10:59
 * @Version: 1.0
 */
@Mapper
public interface OrderMapper extends BaseMapper<Order> {

    // 查询所有的订单
    @Select("SELECT o.id,c.name customerName,o.money,w.name workerName,g.name goodsName,o.time,o.state FROM g_order o,customer c,worker w,goods g WHERE o.cid=c.id and o.wid=w.id and o.gid=g.id")
    List<Order> findAllOrder();

    //通过订单号查看订单
    @Select("SELECT o.id,c.name customerName,o.money,w.name workerName,g.name goodsName,o.time,o.state FROM g_order o,customer c,worker w,goods g WHERE o.cid=c.id and o.wid=w.id and o.gid=g.id and o.id=#{id}")
    Order findOrderById(@Param("id") Integer id);

    @Select("SELECT o.id,c.name customerName,o.money,w.name workerName,g.name goodsName,o.time,o.state FROM g_order o,customer c,worker w,goods g WHERE o.cid=c.id and o.wid=w.id and o.gid=g.id and c.id=#{cid}")
    List<Order> findByCustomerName(@Param("cid") Integer cid);



}
